var g_GBTouchLayer;

var GBTouchLayer = cc.Layer.extend({
	
	map : null,
	writePath : null,
	item : null,
	char : null,
	board : null,

	// 构造函数
	ctor : function(){
		this._super();
		
		g_GBTouchLayer=this;
		
		cc.eventManager.addListener({
			event: cc.EventListener.TOUCH_ONE_BY_ONE,
			swallowTouches: true,
			onTouchBegan: this.onTouchBegan,
			onTouchMoved: this.onTouchMoved,
			onTouchEnded: this.onTouchEnded,
		}, this);
		
		writePath=jsb.fileUtils.getWritablePath();

		this.scheduleUpdate();
		GLReloading();
		this.loadMessage();
	},
	
	
	// 定时器
	update: function () {
		GLLogic();
	},
	
	// 按下事件
	onTouchBegan : function (touch, event) {
		if(_GLState == "等待操作")
			GCDown(ControlManager(touch.getLocation()));
		return true;
	},
	
	// 拖动事件
	onTouchMoved : function (touch, event) {
		if(_GLState == "等待操作")
			GCMove(ControlManager(touch.getLocation()));
	},
	
	// 抬起事件
	onTouchEnded : function (touch, event) {
		if(_GLState == "等待操作")
			GCUp(ControlManager(touch.getLocation()));
	},
	
	// 读取信息
	loadMessage : function (){
		if(_message[_level].length!=0){
			g_GBMessageLayer = new GBMessageLayer(_message[_level]);
			g_GBMessageLayer._messageList=new Array();
			if(getSettingData("skipRead") == "true" && getStartData(_level) == "done"){
				g_GBMessageLayer._messageList.push(new MMMessage (1,"res/head_speech.png",0,0,"既然这段剧情已经看过了，那么跳过也无所谓了。"));
			}
			else if(getSettingData("skipAll") == "true"){
				g_GBMessageLayer._messageList.push(new MMMessage (1,"res/head_speech.png",0,0,"好吧好吧，字太多不看的话，那就跳过吧。"));
			}
			else{
				getStartData(_level);
				g_GBMessageLayer._messageList=_message[_level].concat();
			}
			this.addChild(g_GBMessageLayer,1000);
			if(g_GBMessageLayer.nextMessage()){
				GLNewGame();
			}
		}
		else
			GLNewGame();
	},
	
	// 存储信息
	saveMessage : function (){
		log(jsb.fileUtils.writeToFile(map,writePath+"test.json"));
		map = jsb.fileUtils.getValueMapFromFile("test.json");
	}
});